var express = require('express');
var app = express();
var download163 = require('../download163.js');

// 设置跨域访问
app.all('*',function(req,res,next){
	res.header("Access-Control-Allow-Origin", "*");
	res.header("Access-Control-Allow-Headers", "X-Requested-With");
	res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
	res.header("X-Powered-By",' 3.2.1');
	res.header("Content-Type", "application/json;charset=utf-8");
	next();
});

app.get('/start',function(req,res){
	console.log('接收到分配任务.....');
	console.log('url:'+req.query.url)
    console.log('pas:'+req.query.pas)
    try {
    	console.log('开始执行任务.....');
    	var url = 'http://sports.163.com';
    	new download163(url);
    	res.json({
    		code:200,
    		work:true
    	});

    } catch(e){
    	http404(req,res)
    }
});

var http404 = app.get('/404',function(req,res){
	res.end("404");
});

// 配置服务端口
var server = app.listen(3000,function(){
	var host = server.address(),address;
	var port = server.address().port;
	console.log("正在启动服务器，监听3000.........");
});

